package com.skillscompetition.skillscompetition.controller;


import com.github.pagehelper.PageInfo;
import com.skillscompetition.skillscompetition.bean.Ranking;
import com.skillscompetition.skillscompetition.common.ResponseType;
import com.skillscompetition.skillscompetition.service.impl.RankingServiceImpl;
import com.skillscompetition.skillscompetition.vo.SkillScontestVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lwg
 * @since 2019-11-09
 */
@RestController
@RequestMapping("ranking")
public class RankingController {
    @Autowired
    private RankingServiceImpl rankingService;

    @GetMapping("sort")
    public Map<String, Object> sort() {
        rankingService.sort();
        return ResponseType.success(null);
    }

    @GetMapping
    public Map<String, Object> rankingList(@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "pageSize", defaultValue = "3") Integer pageSize) {
        PageInfo<Ranking> exam = rankingService.rankingList(page, pageSize);
        return ResponseType.success(exam);
    }
    @GetMapping("export")
    public void export(HttpServletResponse response) {
        rankingService.export(response);
    }

}
